package com.boyadegroot.divelog.models;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

public class DiveBuddy implements Parcelable, Comparable<DiveBuddy> {

    private static final String TAG = DiveBuddy.class.getName();

    private long mId;
    private String mName;
    private Diver mDiver;

    public DiveBuddy() {}

    public DiveBuddy(long id, String name, Diver diver) {
        this.setId(id);
        this.setName(name);
        this.setDiver(diver);
    }
    
    public DiveBuddy(long id, String name) {
        this(id, name, null);
    }

    public long getId() {
        return mId;
    }

    public void setId(long id) {
        this.mId = id;
    }

    public String getName() {
        return mName;
    }

    public void setName(String name) {
        this.mName = name;
    }
    
    public Diver getDiver() {
        return mDiver;
    }

    public void setDiver(Diver diver) {
        this.mDiver = diver;
    }

    @Override
    public int compareTo(@NonNull DiveBuddy another) {
        return this.mName.compareTo(another.mName);
    }
    
    @Override
    public String toString() {
        return getName();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(mId);
        dest.writeString(mName);
        dest.writeParcelable(mDiver, flags);
    }

    public static final Parcelable.Creator<DiveBuddy> CREATOR = new Parcelable.Creator<DiveBuddy>() {

        public DiveBuddy createFromParcel(Parcel in) {
            return new DiveBuddy(in);
        }

        public DiveBuddy[] newArray(int size) {
            return new DiveBuddy[size];
        }
    };

    private DiveBuddy(Parcel in) {
        mId = in.readLong();
        mName = in.readString();
        mDiver = in.readParcelable(Diver.class.getClassLoader());
    }
}
